/*
 * CS_GET_HP_BUFF.cpp
 *
 *  Created on: 2014. 6. 16.
 *      Author: the2
 */


#include "../../Command.h"

#include "../../User.h"
#include "../../NLogic/Static.h"
#include "../../NLogic/Battle.h"
#include "../../NLogic/Monster.h"
#include "../../NLogic/Space.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_GET_HP_BUFF(User * pUser, ::Network::Packet *pPacket)
{
/*
	// 버프 오브젝트 삭제
	SN_DESTROY_HP_BUFF	0x142d
	{
		// hp 오브젝트 삭제
	}

	// 버프 획득
	CS_GET_HP_BUFF	0x142e
	{
		U32	u32Seq;	// 획득한 오브젝트의 키전송
	}

	// 버프 획득
	SC_GET_HP_BUFF	0x142f
	{
		s16	s16ack;	// 이미 점유된 seq의 경우 ACK_NO_DATA
	}
*/

	NLogic::Space * pSpace = pUser->GetSpace();
	if (NULL == pSpace)
	{
		DEBUGLOG("CS_GET_HP_BUFF NULL == pSpace");
		return;
	}

	NLogic::Party * pParty = pUser->GetParty();
	if (NULL == pParty)
	{
		DEBUGLOG("CS_GET_HP_BUFF NULL == pParty")
		return;
	}

	PREPARE_PACKET;

	uint32_t objectKey = 0;

	* pPacket >> objectKey;

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();

	if (objectKey != pParty->GetCreateHpBuffKey())
	{
		* pAck << static_cast<int16_t>(ACK_NO_DATA);
		pAck->MakePacket(CMD_SC_GET_HP_BUFF);
		pUser->Send(pAck);
		return;
	}

	pParty->ReSetCreateHpBuffKey(0);

	* pAck << static_cast<int16_t>(ACK_OK);
	pAck->MakePacket(CMD_SC_GET_HP_BUFF);
	pUser->Send(pAck);

	// pUser Buff Setting
	pParty->SetHealBuff(pUser);

	// 다른 유저들에게 SN_DESTROY_HP_BUFF 송신
	::Network::Packet * pNoti = ::Network::GETPACKETPOOL()->SEND_NEW();
	pNoti->MakePacket(CMD_SN_DESTROY_HP_BUFF);
	pSpace->SendAllExceptMe(pNoti, pUser);
}

} /*NCommand*/ } /*ProjectZ*/

